package com.event;


import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;
import java.time.LocalDateTime;

/**
 * @author 大忽悠
 * @create 2022/9/15 20:42
 */
@Getter
@Setter
@ToString
public class DomainEvent extends ApplicationEvent {
    /**
     * 事件ID: 默认是当前时间戳
     */
    private Long eventId;
    /**
     * 事件发布时间: 发布事件的时候自动记录
     */
    private LocalDateTime publishTime;
    /**
     * 是否采用异步事件发送,默认为同步
     */
    private Boolean async=false;
    /**
     * 事件类型: 用常量表或者枚举来列举事件类型
     * 也可以考虑存储到数据库中进行保存
     */
    private Integer eventType;
    /**
     * 事件属于哪一个领域对象,例如: user,manager
     */
    private String domain;

    /**
     * 事件携带的信息是什么
     */
    public DomainEvent(Object info,String domain,Integer eventType) {
        super(info);
        this.publishTime=LocalDateTime.now();
        this.eventId=System.currentTimeMillis();
        this.domain=domain;
        this.eventType=eventType;
    }

    public DomainEvent(Long eventId,Object info,String domain,Integer eventType) {
        super(info);
        this.publishTime=LocalDateTime.now();
        this.eventId=eventId;
        this.domain=domain;
        this.eventType=eventType;
    }

    public DomainEvent(Long eventId,Object info,String domain,Integer eventType,Boolean async) {
        super(info);
        this.publishTime=LocalDateTime.now();
        this.eventId=eventId;
        this.domain=domain;
        this.eventType=eventType;
        this.async=async;
    }
}
